<template>
  <el-container>
    <!-- 头部工具条 -->
    <el-header>
      <div>
        <img
          src="../assets/image/logo.png"
          alt=""
        />
        <span>人事系统管理</span>
      </div>
      <el-button
        type="info"
        @click="goValine()"
      >首页</el-button>
    </el-header>
    <el-container>
      <!-- 左侧菜单条 -->
      <el-aside :width="isCollapse ? '50px' : '200px'">
        <el-menu
          mode="vertical"
          default-active="0"
          :router='true'
        >
          <el-submenu
            v-for="item in menuList"
            :index="'/' + item.path"
            :key="item.id"
          >
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{item.menuName}}</span>
            </template>
            <el-menu-item
              :index="'/' + item1.path"
              :key="item1.id"
              v-for="item1 in item.subMenu"
            >
              <template slot="title">
                <i :class="item1.icon"></i>
                <span>{{item1.menuName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <!-- 路由占位符 -->
          <router-view></router-view>
        </el-main>
        <el-footer height="">
          <!-- Footer content -->
        </el-footer>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
import { homeMixin } from '../utils/mixin'
export default {
  mixins: [homeMixin],
  data () {
    return {
    }
  },
  created () {
    this.getMenuList()
  },
  methods: {
    // 退出登录
    logout () {
      window.sessionStorage.clear()
      this.$router.replace('/login')
    },
    goValine () {
      if (this.$route.path !== '/home/valine') {
        this.$router.replace('/home/valine')
      }
      this.$router.go(0)
    },
    // 获取主页左侧菜单数据
    async getMenuList () {
      const { data: res } = await this.$http.get('/home/menus')
      if (res.error_code === 0) {
        // 此变量需要在各个多个组件的面包屑导航中使用，所以存入vuex，this.setMenuList()为唯一改变menuList值得方法
        this.setMenuList(res.data)
      } else {
        return res.msg
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.el-container {
  height: 100%;
  .el-header {
    background-color: #393d3f;
    color: #fff;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    div {
      display: flex;
      align-items: center;
      height: 100%;
      img {
        margin-right: 40px;
        padding-left: 20px;
        height: 100%;
      }
      span {
        font-size: 20px;
      }
    }
    .el-button {
      margin-right: 20px;
    }
  }
  .el-container {
    .el-aside {
      // background-color: #343742;
      .el-menu {
        border: 0;
        .el-submenu {
          .iconfont {
            margin-right: 10px;
          }
        }
      }
    }
    .el-main {
      background-color: #eaedf0;
      color: #333;
    }
  }
}
</style>
